package leetcode.D300.T232;

import java.util.Deque;
import java.util.LinkedList;

/**
 * @File Info: leetcode -- <MyQueue>
 * @Author: DYZ
 * @Create: 2022-02-18 16:39:09
 */

class MyQueue {

    Deque<Integer> dq1 = new LinkedList<>();
    Deque<Integer> dq2 = new LinkedList<>();

    public MyQueue() {
    }

    public void push(int x) {
        dq1.push(x);
    }

    public int pop() {
        if (dq2.isEmpty()) {
            while (!dq1.isEmpty()) {
                dq2.push(dq1.poll());
            }
        }
        return dq2.pop();
    }

    public int peek() {
        if (dq2.isEmpty()) {
            while (!dq1.isEmpty()) {
                dq2.push(dq1.poll());
            }
        }
        return dq2.peek();
    }

    public boolean empty() {
        return dq1.isEmpty() && dq2.isEmpty();
    }
}